package com.vq3.digitalizationsoftwareintegrates.Service.Index.Impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.vq3.digitalizationsoftwareintegrates.Entity.Index.SoftWares_Role_tbEntity;
import com.vq3.digitalizationsoftwareintegrates.Entity.Index.SoftwaresEntity;
import com.vq3.digitalizationsoftwareintegrates.Entity.User.User_RoleEntity;
import com.vq3.digitalizationsoftwareintegrates.Mapper.Index.SoftWaresMapper;
import com.vq3.digitalizationsoftwareintegrates.Mapper.Index.SoftWares_Role_tbMapper;
import com.vq3.digitalizationsoftwareintegrates.Mapper.User.User_RoleMapper;
import com.vq3.digitalizationsoftwareintegrates.Service.Index.IndexSoftwareService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class IndexSoftwareServiceImpl implements IndexSoftwareService {
    @Resource
    User_RoleMapper user_roleMapper;
    @Resource
    SoftWares_Role_tbMapper softWares_role_tbMapper;


    final
    SoftWaresMapper softWaresMapper;

    public IndexSoftwareServiceImpl(SoftWaresMapper softWaresMapper) {
        this.softWaresMapper = softWaresMapper;
    }

    @Override
    public List<SoftwaresEntity> findAll(List<User_RoleEntity> user_roleEntities) {
        QueryWrapper<SoftWares_Role_tbEntity> softWares_role_tbEntityQueryWrapper = new QueryWrapper<>();
        for (User_RoleEntity user_roleEntity : user_roleEntities) {
            softWares_role_tbEntityQueryWrapper.or().eq("rid",user_roleEntity.getUroleId());
        }
        List<SoftWares_Role_tbEntity> softWares_role_tbEntities = softWares_role_tbMapper.selectList(softWares_role_tbEntityQueryWrapper);

        QueryWrapper<SoftwaresEntity> wrapper = new QueryWrapper<>();
        for (SoftWares_Role_tbEntity softWares_role_tbEntity : softWares_role_tbEntities) {
            wrapper.or().eq("sid",softWares_role_tbEntity.getSwid());
        }

        return softWaresMapper.selectList(wrapper);
    }

    public List<User_RoleEntity> uidFindRid(int uid){
        QueryWrapper<User_RoleEntity> userRoleEntityQueryWrapper = new QueryWrapper<>();
        userRoleEntityQueryWrapper.eq("user_id",uid);
        return user_roleMapper.selectList(userRoleEntityQueryWrapper);
    }


}
